<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    let getUserInfo = function () {
      return new Promise((resolve, reject) => {
        setTimeout(() => resolve('姓名：yzx'),
          Math.floor(Math.random() * 400));
      })
    }

    let showUserInfo = function (user) {
      return getUserInfo()
        .then(info => {
          console.log('用户信息', info);
          return true
        })
    }

    let timeout = function (delay) {
      return new Promise(resolve => {
        setTimeout(() => resolve(), delay);
      })
    }
    let time
    let showToast = function () {
      time = +new Date()
      console.log('show loading');
    }

    let hideToast = function () {
      console.log('hide loading' + (+new Date() - time))
    }

    Promise.race([showUserInfo(), timeout(200)])
      .then((display) => {
        console.log(display, '++++++++');
        if (!display) {
          showToast()
          Promise.all([showUserInfo(), timeout(200)])
            .then(() => {
              hideToast()
            })
        }
      })
  </script>
</body>

</html>